package com.higgins.eventtracking.client.health.overview;

import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.higgins.eventtracking.client.health.ActionTab;
import com.higgins.eventtracking.client.health.Fundamentals;

public class GoalsTab extends VerticalPanel 		{
	private boolean firstRun = true;
	private TabPanel tabPanel = new TabPanel();
	private ActionTab parentTab = null;
	
	private String relationship = "Relationship";
	private String legalCareer = "Legal Career";
	private String buildForFuture = "Build For The Future";
	private String houseKeeping = "House Keeping";
	private String currentCareer = "Current Career";
	private String relax = "Relax";
	private String social = "Social";
	
	private Integer tab1 = null;
	private Integer tab2 = null;
	private Integer tab3 = null;
	private Integer tab4 = null;
	private Integer tab5 = null;
	private Integer tab6 = null;
	private Integer tab7 = null;
		
	private GoalsSubTab houseKeepingTab = new GoalsSubTab(this, houseKeeping);
	private GoalsSubTab buildForFutureTab = new GoalsSubTab(this, buildForFuture);
	private GoalsSubTab lawCareerTab = new GoalsSubTab(this, legalCareer);
	private GoalsSubTab currentCareerTab = new GoalsSubTab(this, currentCareer);
	private GoalsSubTab relaxTab = new GoalsSubTab(this, relax);
	private GoalsSubTab relationshipTab = new GoalsSubTab(this, relationship);
	private GoalsSubTab socialTab = new GoalsSubTab(this, social);

	
	public GoalsTab(ActionTab parentTab)	{
		this.parentTab = parentTab;
		setHeight("35em");
	}
	public void update()	{
		if (firstRun)	
			initialise();
	}
	public void initialise()	{
		populateTabPanel();
		firstRun = false;
	}
	public void populateTabPanel()	{
//		relationshipTab.update();
//		lawCareerTab.update();
//		buildForFutureTab.update();
//		houseKeepingTab.update();
//		currentCareerTab.update();
//		relaxTab.update();
//		socialTab.update();
		addTabs();
		add(tabPanel);
		houseKeepingTab.update();
		tabPanel.addSelectionHandler(createSelectionHandler());
	}
	public SelectionHandler<Integer> createSelectionHandler()	{
		SelectionHandler<Integer> selectionHandler = new SelectionHandler<Integer>() {
	        @Override
	        public void onSelection(SelectionEvent<Integer> integerSelectionEvent) {
	            if (integerSelectionEvent.getSelectedItem() == 0)	{
	            	houseKeepingTab.update();
	            }
	            if (integerSelectionEvent.getSelectedItem() == 1)	{
	            	buildForFutureTab.update();
	            }
	            if (integerSelectionEvent.getSelectedItem() == 2)	{
	            	lawCareerTab.update();
	            }
	            if (integerSelectionEvent.getSelectedItem() == 3)	{
	            	currentCareerTab.update();
	            }
	            if (integerSelectionEvent.getSelectedItem() == 4)	{
	            	relaxTab.update();
	            }
	            if (integerSelectionEvent.getSelectedItem() == 5)	{
	            	relationshipTab.update();
	            }	            
	            if (integerSelectionEvent.getSelectedItem() == 6)	{
	            	socialTab.update();
	            }
	        }
		};
		return selectionHandler;
	}
//	public void setSubHeaderCount(String header, int count)	{
//		if (header.equals(relationship))	{
//			tab1 = count;
//		} else if (header.equals(legalCareer))	{
//			tab2 = count;
//		} else if (header.equals(buildForFuture))	{
//			tab3 = count;
//		}  else if (header.equals(houseKeeping))	{
//			tab4 = count;
//		}  else if (header.equals(currentCareer))	{
//			tab5 = count;
//		}  else if (header.equals(relax))	{
//			tab6 = count;
//		}  else if (header.equals(social))	{
//			tab7 = count;
//		} 
//		passBackToParent();
//	}
//	private void passBackToParent()	{
//		if (tab1!=null && tab2!=null && tab3!=null && tab4!=null && tab5!=null && tab6!=null && tab7!=null)	{
//			addTabs();
//			parentTab.addGoalsTab();
//		}
//	}
	private void addTabs()	{
		tabPanel.add(houseKeepingTab, houseKeeping);
		tabPanel.selectTab(0);
		tabPanel.add(buildForFutureTab, buildForFuture);
		tabPanel.add(lawCareerTab, legalCareer);
		tabPanel.add(currentCareerTab, currentCareer);				
		tabPanel.add(relaxTab, relax);
		tabPanel.add(relationshipTab, relationship);
		tabPanel.add(socialTab, social);
//		tabPanel.selectTab(0);
	}
}
